package com.bestow.basic.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.bestow.common.annotation.Log;
import com.bestow.common.core.controller.BaseController;
import com.bestow.common.core.domain.AjaxResult;
import com.bestow.common.enums.BusinessType;
import com.bestow.basic.domain.HlsDbDataSource;
import com.bestow.basic.service.IHlsDbDataSourceService;
import com.bestow.common.utils.poi.ExcelUtil;
import com.bestow.common.core.page.TableDataInfo;

/**
 * 通用数据源定义Controller
 * 
 * @author liliu
 * @date 2022-09-14
 */
@RestController
@RequestMapping("/basic/dbDataSource")
public class HlsDbDataSourceController extends BaseController
{
    @Autowired
    private IHlsDbDataSourceService hlsDbDataSourceService;

    /**
     * 查询通用数据源定义列表
     */
    @PreAuthorize("@ss.hasPermi('basic:dbDataSource:list')")
    @GetMapping("/list")
    public TableDataInfo list(HlsDbDataSource hlsDbDataSource)
    {
        startPage();
        List<HlsDbDataSource> list = hlsDbDataSourceService.selectHlsDbDataSourceList(hlsDbDataSource);
        return getDataTable(list);
    }

    /**
     * 导出通用数据源定义列表
     */
    @PreAuthorize("@ss.hasPermi('basic:dbDataSource:export')")
    @Log(title = "通用数据源定义", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HlsDbDataSource hlsDbDataSource)
    {
        List<HlsDbDataSource> list = hlsDbDataSourceService.selectHlsDbDataSourceList(hlsDbDataSource);
        ExcelUtil<HlsDbDataSource> util = new ExcelUtil<HlsDbDataSource>(HlsDbDataSource.class);
        util.exportExcel(response, list, "通用数据源定义数据");
    }

    /**
     * 获取通用数据源定义详细信息
     */
    @PreAuthorize("@ss.hasPermi('basic:dbDataSource:query')")
    @GetMapping(value = "/{dataSourceId}")
    public AjaxResult getInfo(@PathVariable("dataSourceId") Long dataSourceId)
    {
        return AjaxResult.success(hlsDbDataSourceService.selectHlsDbDataSourceByDataSourceId(dataSourceId));
    }

    /**
     * 新增通用数据源定义
     */
    @PreAuthorize("@ss.hasPermi('basic:dbDataSource:add')")
    @Log(title = "通用数据源定义", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HlsDbDataSource hlsDbDataSource)
    {
        return toAjax(hlsDbDataSourceService.insertHlsDbDataSource(hlsDbDataSource));
    }

    /**
     * 修改通用数据源定义
     */
    @PreAuthorize("@ss.hasPermi('basic:dbDataSource:edit')")
    @Log(title = "通用数据源定义", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HlsDbDataSource hlsDbDataSource)
    {
        return toAjax(hlsDbDataSourceService.updateHlsDbDataSource(hlsDbDataSource));
    }

    /**
     * 删除通用数据源定义
     */
    @PreAuthorize("@ss.hasPermi('basic:dbDataSource:remove')")
    @Log(title = "通用数据源定义", businessType = BusinessType.DELETE)
	@DeleteMapping("/{dataSourceIds}")
    public AjaxResult remove(@PathVariable Long[] dataSourceIds)
    {
        return toAjax(hlsDbDataSourceService.deleteHlsDbDataSourceByDataSourceIds(dataSourceIds));
    }
}
